home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
tcomm50.zip
/
QBTTL.C
< prev
next >
Wrap
Text File
|
1989-07-31
|
25KB
|
1,101 lines
/*
** QBTTL is a complete, if somewhat limited, terminal emulation
** program designed to demonstrate the use of the LiteComm(tm)
** ToolBox. The executable version is included so that you can
** try it out while viewing the code. To successfully create a
** new version of QBTTL, you must have the XMODEM and WXMODEM engines
** which are provided as part of your registration package. The
** QUICKB functionality is derived from public domain code, and adapted
** by Information Technology for use with LiteComm.
** Also note that the windowing parts of the program are based upon
** Vitamin-C by Creative Programming. You must have this product and
** be a registrant to successfully compile a new version of QBTTL.
**
** While non-registered users cannot create a new version of QBTTL, as-is
** we have provided the source as part of the distribution package to
** help you in your understanding of the way in which the LiteComm
** Communications ToolBox can be used.
**
** QBTTL functions as a vidtex terminal when used in conjuction with
** CompuServe. In addition, it will run on any communications port from
** 1 thru 4, defaulting to port 2 (COM2). To execute QBTTL on other than
** COM2, specify
** QBTTL n
** where n is a number from 1 to 4.
**
** Please note also that, to send a Ctrl-C, you must use the Alt-C keys
**
** Information Technology, Ltd.
*/
#include "litecomm.h"
#include "litexm.h"
#include <vcstdio.h>
#ifdef __TURBOC__
#include <stdlib.h>
#include <dos.h>
#include <fcntl.h>
#include <sys\stat.h>
#include <io.h>
#include <mem.h>
#endif
#ifdef M_I86
#include <signal.h>
#include <conio.h>
#include <ctype.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys\types.h>
#include <sys\stat.h>
#endif
#ifdef __TURBOC__
extern unsigned _stklen = 8192;
#endif
#define CTRLX 0x18
#define ESC 0x1b
#define ENQ 0x05
int nocbrk();
void moveleft();
void moveright();
void moveup();
void movedn();
void show_modem();
void simtab();
void setcursorpos();
void procesc();
void clreos();
void send(void);
void recv(void);
void xupload(void);
void xdnload(void);
void wupload(void);
void wdnload(void);
/*
** Comm parameters - human-readable form
*/
int baud = 2400;
char parity = 'N';
int data = 8;
int stop = 1;
/*
** Comm parameters - Litecomm form
*/
unsigned pbaud = 2400;
unsigned pparity = NPARITY;
unsigned pbits = BIT8;
unsigned pstop = STOP1;
unsigned port = 2;
int xmode = 0; /* xmodem type */
int yxmode = 0; /* use small blocks */
int halfd = 0; /* half-duplex */
int hostm = 0; /* host mode */
int ctlc_hit = FALSE;
char MODEMSET0[] = "ATZ\r";
char MODEMSET1[] = "ATT E0\r";
char MODEMSET2[] = "ATC1 V0 X1 S0=1 M1\r";
COUNT mwin; /* for Vitamin-C */
COUNT swin;
COUNT mbd;
COUNT mbg;
COUNT msay;
COUNT mact;
COUNT mnact;
COUNT mtitle;
COUNT sbd;
COUNT sbg;
COUNT ssay;
COUNT sact;
COUNT snact;
COUNT stitle;
char strbuf[80]; /* for sprintf usage */
void main(argc, argv)
int argc;
char *argv[];
{
COUNT opt;
#ifdef M_I86
signal(SIGINT, nocbrk); /* set Ctrl-Break handler */
#endif
#ifdef __TURBOC__
ctrlbrk(nocbrk);
#endif
/*
** check for a port parameter
*/
if (argc > 1)
{
port = atoi(argv[1]);
if ((port < 1) || (port > 4))
{
puts("Invalid Port Specified\n");
exit(4);
}
}
/*
** establish windowing environment
*/
vcstart(SAVESCRN);
VC_VIO = 1;
if ((mwin=wxopen(0,0,23,79,NULL,
ACTIVE+CURSOR+SCROLL+COOKED+NOADJ+CENTER, 0, 0)) == -1)
terror("mwin:Not Enough Memory");
if ((swin=wxopen(24,0,24,79,NULL,
ACTIVE+COOKED+NOADJ, 0, 0)) == -1)
terror("swin:Not Enough Memory");
wselect(mwin);
/*
** get display attributes
*/
wattr(mwin,&mbd, &mbg, &msay, &mact, &mnact, &mtitle, GET);
wattr(swin,&sbd, &sbg, &ssay, &sact, &snact, &stitle, GET);
/*
** set-up the comm port
*/
if (comm_opn(port,2400,NPARITY,BIT8,STOP1,2048,2048,FALSE) == -1)
{
urgentmsg("ERROR", "Can't open port");
abort();
}
lc_setmdm(port, (DTR | RTS));
while (1)
{
erase();
at(0,0);
vcputs("-- MAIN MENU --\r", msay);
vcputs("T - enter Terminal mode\r", msay);
vcputs(" Alt-X leaves terminal mode\r", msay);
sprintf(strbuf, "H - toggle Host mode (now %s)\r",hostm ? "ON":"OFF");
vcputs(strbuf, msay);
sprintf(strbuf, "G - toGgle half-duplex mode (now %s)\r",halfd ? "ON":"OFF");
vcputs(strbuf, msay);
sprintf(strbuf, "C - change Comm parameters (now %d,%c,%d,%d)\r",
baud,parity,data,stop);
vcputs(strbuf, msay);
sprintf(strbuf, "X - change Xmodem mode (now %s)\r",xmode ? "WIN":"NOR");
vcputs(strbuf, msay);
sprintf(strbuf, "Y - toggle Ymodem mode (now %s)\r",yxmode ? "ON":"OFF");
vcputs(strbuf, msay);
vcputs("S - Send a file\r", msay);
vcputs("R - Receive a file\r", msay);
vcputs("Q - Quit\r\r", msay);
opt = getone();
opt = toupper(opt);
switch (opt)
{
case 'T': terminal();
break;
case 'H': if (hostm)
hostm = 0;
else
{
hostm = 1;
halfd = 0;
}
break;
case 'G': if (halfd)
halfd = 0;
else
{
halfd = 1;
hostm = 0;
}
break;
case 'X': if (xmode)
xmode = 0;
else
xmode = 1;
break;
case 'Y': if (yxmode)
{
ymodem = FALSE;
yxmode = 0;
}
else
{
yxmode = 1;
ymodem = TRUE;
}
break;
case 'S': send();
break;
case 'R': recv();
break;
case 'C': chgcomm();
break;
}
if (opt == 'Q')
break; /* shut down time */
} /* while (1) */
comm_close(port,FALSE);
vcend(CLOSE);
exit(0);
} /* main */
int nocbrk()
{
#ifdef M_I86
signal(SIGINT, SIG_IGN); /* set Ctrl-Break handler */
#endif
ctlc_hit = TRUE;
_abort_flag = TRUE;
#ifdef M_I86
signal(SIGINT, nocbrk); /* set Ctrl-Break handler */
#endif
return(TRUE);
}
terminal()
{
COUNT ch;
COUNT row, col;
COUNT twin;
erase();
lc_xoff(port,TRUE);
while (1)
{
if ((ch = lc_get(port)) != -1)
switch (ch & 0x7f)
{
case 0x08: /* BS */
moveleft();
vcputc(' ', msay);
moveleft();
break;
case '\t': /* HT */
simtab();
break;
case '\r': /* CR */
wcurspos(mwin, &row, &col);
at(row,0);
break;
case DLE:
twin=wxopen(6,20,13,60,"TRANSFER A FILE",
BORDER+BD1+ACTIVE+CURSOR+SCROLL+COOKED+NOADJ+CENTER, 0, 0);
wselect(twin);
bp_DLE();
wclose(twin);
wselect(mwin);
break;
case ENQ:
bp_ENQ();
break;
case ESC:
procesc();
break;
default:
if (pparity != NPARITY)
ch &= 0x7f; /* strip parity */
vcputc(ch, msay);
if (hostm)
{
lc_put(port,ch); /* echo back */
if (ch == '\r') /* was it return */
{
lc_put(port,'\n'); /* echo lf as well */
vcputc('\n', msay);
}
}
}
show_modem (lc_mstat(port));
if (keyrdy()) /* anything typed ? */
{
ch = getone(); /* get input */
if (ch == ALT_X)
return(0);
if (ch == ALT_C)
ch = 0x03;
lc_put(port,ch); /* xmit the char */
if (hostm || halfd) /* local echo needed ? */
{
vcputc(ch, msay);
if (ch == '\r') /* was it CR */
{
vcputc('\n', msay); /* add LF */
if (hostm)
lc_put(port, '\n'); /* and send LF in host mode */
}
}
}
} /* while */
}
void procesc()
{
int ch;
ch = lc_getw(port); /* wait for actual comm